/**
 *******************************************************************************
 * @file user_global.h
 * @author .ISS_AUTO (hudandan@issauto.com)
 * @date 2024-09-13
 *
 * @brief xxx
 *
 * @copyright Copyright (c) 2024 ISSAUTO TECH Co., Ltd. All rights reserved.
 *
 *******************************************************************************
 */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USER_GLOBAL_H_
#define __USER_GLOBAL_H_

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "user_config.h"

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdbool.h>
#include <math.h>

/* Exported types ------------------------------------------------------------*/

/** @addtogroup 数据类型定义
  * @{
  */

typedef enum {FALSE = 0, TRUE = !FALSE} u_bool;

/**!* @brief  Task Status structures definition
 */
typedef enum {
    TASK_STATE_INIT = 0U,
    TASK_STATE_ACTIVE,
    TASK_STATE_PROCESSING,
    TASK_STATE_INACTIVE,
    TASK_STATE_IDLE,

    TASK_STATE_INVALID,
} TaskState_t;

/**!* @brief  DRV Status structures definition
 */
typedef enum {
    DRV_OK       = 0x00U,
    DRV_ERROR    = 0x01U,
    DRV_BUSY     = 0x02U,
    DRV_TIMEOUT  = 0x03U,
    DRV_IDLE     = 0x04U
} DRV_StatusTypeDef;

/**
  * @}
  */

/* Exported constants --------------------------------------------------------*/
#define APP_ERR_CODE_RST_MASK        (0xFFFF0000UL) /* Reset Msk */
#define APP_ERR_CODE_RST_DEV         (0x00010000UL) /* Driver Layer error */
#define APP_ERR_CODE_RST_SLEEP       (0x00020000UL) /* Sleep error */

#define APP_ERR_CODE_FAULT_MASK      (0x0000FFFFUL) /* Fault error */

/* Exported macro ------------------------------------------------------------*/

/** @addtogroup software timer configure
  * @{
  */
#include "swTimer.h"

typedef uint32_t    STimerType; //!< Data type for time representation (32 bit (= 0xFFFFFFFF ms) -> wrap around every ~49 days)

#define STIMER_GET()                     (STimerType)swt_GetTickCount()
#define STIMER_IS_TIMEOUT(start, time)   swt_IsTimeout(start, time)

#define STIMER_RESET()                   swt_RstTickCount()
#define STIMER_mDELAY(ms)                swt_Delay(ms)

/**
  * @}
  */



/** @addtogroup Debug-Printf
  * @{
  */
#define FILE_NAME()    (strrchr(__FILE__,'\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)     //!< windows
// #define FILE_NAME()    (strrchr(__FILE__,'/') ? strrchr(__FILE__, '/') + 1 : __FILE__)       //!< linux

/** @note Log 打印通道使能设置 (Default 1) */
#if !defined(LOG_ENABLE)
#define LOG_ENABLE                    (1U)
#endif

#if (LOG_ENABLE)
#define USER_PRINTF(M, ...)     printf(M, ##__VA_ARGS__)

#define USER_LOG_DEBUG(M, ...)    \
    USER_PRINTF("[%d][%s:%4d] "M"\r\n", STIMER_GET(), FILE_NAME(), __LINE__, ##__VA_ARGS__)

#define USER_LOG_ERR(M, ...)    \
    USER_PRINTF("[ERR][%d][%s:%4d] "M"\r\n", STIMER_GET(), FILE_NAME(), __LINE__, ##__VA_ARGS__)

#else
#define USER_PRINTF(M, ...)

#define USER_LOG_DEBUG(M, ...)

#define USER_LOG_ERR(M, ...)

#define USB_PRINTF(M, ...)

#endif

/**
  * @}
  */



/* Exported function prototypes -----------------------------------------------*/
/* Exported functions ---------------------------------------------------------*/



#ifdef __cplusplus
}
#endif

#endif /* __USER_GLOBAL_H_ */

/* END OF FILE ---------------------------------------------------------------*/
